#include "building.h"
#include "error.h"

building::building(uicoord ps,uicoord sz): pos( ps ), size( sz ){}
building::building(unsigned int x,unsigned int y,unsigned int w,unsigned int h){
    pos.x = x;
    pos.y = y;
    size.x = w;
    size.y = h;
}

void building::execAI(clock_t now){}

void building::install(map* mymap){
    for( unsigned int i = 0; i < size.x; i++ ){
        for( unsigned int j = 0; j < size.y; j++ ){
            map_elem* el = mymap->elem( i + pos.x, j + pos.y );
            if( !(el->status & sta_bldg) ){
                error::log(error::con_only,"Map Update: Batiment en (%d,%d)\n", i + pos.x, j + pos.y);
                el->status |= sta_bldg;
            }
        }
    }
}

bool building::hasSpace(map* mymap){
    for( unsigned int i = 0; i < size.x; i++ ){
        for( unsigned int j = 0; j < size.y; j++ ){
            if( !map::isBuildable(mymap->elem( i + pos.x, j + pos.y )) ) return false;
        }
    }
    return true;
}
